/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package op;

import core.CreateConta;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Jônatas
 */
public class CreateContaSiemens implements CreateConta {

    public ContaTelefonica createConta(String[] fullFile) throws Exception {

        ContaTelefonica contaTelefonica = new ContaTelefonica();

        contaTelefonica.contaMensal = new ArrayList<EntradaAbstrata>();
        Map<String, Object> parametersMap = null;

        for (String line : fullFile) {
            line = line.trim();

            if (line.isEmpty()) {
                continue;
            }

            String first = line.split("[ \\t]+")[0];

            if(!first.matches("[0-9]{2}.[0-9]{2}.[0-9]{2}")) {
                continue;
            }

            parametersMap = new HashMap<String, Object>();
            parametersMap.put("line", line);

            EntradaAbstrata entrada = new QuebraStringSiemens().quebraString(parametersMap);

            if (entrada != null) {
                contaTelefonica.contaMensal.add(entrada);
            }

        }

        Collections.sort(contaTelefonica.contaMensal, new ComparatorEntradaAbstrataPorTelefone());

        contaTelefonica.contaResumida();

        return contaTelefonica;

    }
}
